<template>
    <div>
        <h3>房号增加</h3>
        <table class="table table-bordereds">
            <tbody>
                <tr>
                    <td align="right">房号名称</td>
                    <td>
                        <input type="text" v-model="info.houseNoName">
                    </td>
                </tr>
                <tr>
                    <td align="right">房型名称</td>
                    <td>
                        <select v-model="info.houseTypeId">
                            <option value="">请选择</option>
                            <option :value="item.houseTypeId" v-for="item in data.list">{{ item.houseTypeName }}
                            </option>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td align="right">房态</td>
                    <td>
                        <select v-model="info.houseState">
                            <option :value=0>请选择</option>
                            <option :value="1">空闲</option>
                            <option :value="2">已入住</option>
                            <option :value="3">已预约</option>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td></td>
                    <td>
                        <input type="button" value="增加" class="btn btn-success" @click="add">
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import { ref, reactive, onMounted, registerRuntimeCompiler } from 'vue'
import axios from 'axios';
import { useRouter, useRoute } from 'vue-router';
const router = useRouter();
const route = useRoute();
onMounted(() => {
    Show();
})
//参数
let type: any = reactive({
    pageindex: 1,
    pagesize: 100,
    housetypename: '',
    area1: '',
    area2: ''
})
//后端
let data: any = reactive({
    listcount: '',
    pagecount: '',
    list: []
})
const Show = () => {
    axios({
        url: '/api/HouseType/GetHouseTypeList',
        method: 'get',
        params: type
    })
        .then((res) => {
            console.log(res);
            Object.assign(data, res.data)
        })
        .catch((err) => {
            console.log(err);

        })
}
let info = reactive({
    "houseNoName": "",
    "houseTypeId": '',
    "houseState": 1
})
const add = () => {
    if (info.houseNoName == "") {
        alert('房号名称不能为空')
        return
    }
    if (info.houseTypeId == "") {
        alert('房型必选')
        return
    }
    if (info.houseState == 0) {
        alert('房态必选')
        return
    }
    axios({
        url: '/api/HouseType/AddHouseNo',
        method: 'post',
        data: info
    })
        .then((res) => {
            console.log(res);
            if (res.data == -1) {
                alert('名称重复')
                return
            }
            if (res.data > 0) {
                alert('添加成功')
                router.push('/houseNoList')
                return
            }
            else {
                alert('添加失败')
            }
        })
        .catch((err) => {
            console.log(err);

        })
}
</script>

<style scoped></style>